/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package controlador;

import Persistencia.PersistenciaUsuario;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import logica.Usuario;

/**
 *
 * @author JAVA
 */
public class mensajes extends HttpServlet {

    /** 
     * Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods.
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        response.setContentType("text/html;charset=UTF-8");
        PrintWriter out = response.getWriter();
        ArrayList<Usuario> lista = logica.Usuario.getListaAmigos((String)request.getAttribute("nick"));
        try {
      out.write("\n");
      out.write("\n");
      out.write("\n");
      out.write("<!DOCTYPE html>\n");
      out.write("<html>\n");
      out.write("    <head>\n");
      out.write("        <meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\">\n");
      out.write("        <title>JSP Page</title>\n");
      out.write("    </head>\n");
      out.write("    <body>\n");
      out.write("        <h1>MENSAJES</h1>\n");
      out.write("        <div class=\"AñadirMensaje\">\n");
      out.write("            <span style=\"float: left; padding-top: 2px;\"></span><input id=\"xs\" value=\"Añadir Mensaje\" style=\"margin-left: 50px; padding: 0px; width: 120px; font-size: 14px; font-family: trebuchet ms;\" onclick=\"if(this.parentNode.getElementsByTagName('div')[0].style.display != ''){this.parentNode.getElementsByTagName('div')[0].style.display = '';this.value = 'Ocultar';}else{this.parentNode.getElementsByTagName('div')[0].style.display = 'none'; this.value = 'Añadir Mensaje';}\" type=\"button\" /><div class=\"spoiler\" style=\"display: none;\">\n");
      out.write("               <form method=\"post\" action=\"enviaMensaje\" id=\"<enviaInv_form\">\n");
      out.write("                   ListaAmigos\n");
                out.println("<table cellspacing=\"5\" cellpadding=\"5\" border=\"1\" width=\"300\">");
                out.println("<tr><th>DNI</th><th>NOMBRE</th></tr>");
                out.println("<select name=\"Amigos\">");
                for(Usuario c2: lista){
                    out.println("<OPTION VALUE="+c2.getIdUsuario()+">"+c2.getUsuario()+"</OPTION>");
                }
                out.println("</select>");
                out.println("</table>");
      out.write("                   <textarea COLS=20 ROWS=10 NAME=\"Texto\">\n");
      out.write("                    </textarea> \n");
      out.write("                   <input type='submit' value='Enviar'>\n");
      out.write("               </form>\n");
      out.write("\n");
      out.write("        </div>\n");
      out.write("        <table cellspacing=\\\"5\\\" cellpadding=\\\"5\\\" border=\\\"1\\\" width=\\\"300\\\">\n");
      out.write("            <tr><th>NombreAmigo</th><th>Mensaje</th></tr>\n");
      out.write("            <tr><th>AmigoRafa1</th><th>por donde andas amigoo</th><th><li><a href=\"#menuh\">Borrar Mensaje</a></li></th></tr>\n");
      out.write("</table>\n");
      out.write("\n");
      out.write("</body>\n");
      out.write("</html>\n");
        } finally {            
            out.close();
        }
    }

    // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
    /** 
     * Handles the HTTP <code>GET</code> method.
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        processRequest(request, response);
    }

    /** 
     * Handles the HTTP <code>POST</code> method.
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        processRequest(request, response);
    }

    /** 
     * Returns a short description of the servlet.
     * @return a String containing servlet description
     */
    @Override
    public String getServletInfo() {
        return "Short description";
    }// </editor-fold>
}
